package com.java.admin.admin.service;

import com.java.admin.exception.BusinessException;
import com.java.database.entity.Caradmininfo;
import com.java.database.mapper.CaradmininfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class LoginService {

    @Autowired
    private CaradmininfoMapper caradmininfoMapper;

    /**
     * 验证登录信息
     */
    public Caradmininfo login(String adminName,String adminPwd){
        if("".equals(adminName)||adminName==null||"".equals(adminPwd)||adminPwd==null) {
            throw new RuntimeException("用户名或密码不能为空！");
        }
        Caradmininfo caradmininfo = new Caradmininfo();
        caradmininfo.setAdminname(adminName);
        caradmininfo.setAdminpwd(adminPwd);
        Caradmininfo caradmininfo1 = caradmininfoMapper.query(caradmininfo);
        if(caradmininfo1==null){
            throw  new RuntimeException("用户名或密码错误！");
        }
        return  caradmininfo1;
    }

    /**
     * 查询管理员信息
     */
    public Caradmininfo queryAdmin(String adminName){
        if(adminName==null||"".equals(adminName)){
            throw new RuntimeException("用户名不能为空！");
        }
        Caradmininfo caradmininfo = caradmininfoMapper.queryAdmin(adminName);
        if(caradmininfo==null){
            throw new RuntimeException("查询管理员信息失败！");
        }
        return  caradmininfo;

    }
    /**
      *通过管理员账户修改管理员信息
      */
    public void updateadmininfo(Caradmininfo caradmininfo){
        caradmininfoMapper.updateadmin(caradmininfo);
    }

    /**
     * 添加
     */

    public  void addadmin(Caradmininfo caradmininfo){
        caradmininfoMapper.insert(caradmininfo);
    }
}
